﻿@{
    ViewBag.Title = "新建无保单报案";
    var provinceList = ServiceFactory.D_ProvinceServiceInstance.GetDProvinceAll();
    var selectList = new SelectList(provinceList, "ProvinceID", "ProvinceName");
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Certificate
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.Common.Enums.InsuranceOrder
@using ZBJF.Warranty.Common.Enums.InsuranceOrder.Data
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord

@using (Html.BeginForm("SaveNoInsuranceOrderIWR", "InsuranceWarrantyRecord", FormMethod.Post, new { id = "mvcForm", name = "mvcForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    @Html.HiddenFor(c => c.InsuranceOrderId)
    <h4>基本信息</h4>
    <table class="table table-responsive table-bordered table-hover">
        <tr>
            <th class="w200">保险产品类型：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.InsuranceCategoryName, new { Value = "碎屏险", @class = "disabled-element" })
            </td>
            <th class="w200">保险产品名称：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.ProductName, new { Value = "碎屏险", @class = "disabled-element" })
            </td>
        </tr>
        <tr>
            <th>被保险设备：</th>
            <td>
                @Html.DropDownListFor(m => m.InsuranceOrder.ProductTypeId, ConvertToSelector.Instance.ProductTypeConvertToSelectList(false), new { onchange = "productTypeChange()" })
                @Html.HiddenFor(m => m.InsuranceOrder.ProductTypeName)
            </td>
            <th>证件类型</th>
            <td>
                @Html.DropDownListFor(m => m.InsuranceOrder.CertificateType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(UserCertificateType), addEmptySelect: false))
            </td>
        </tr>
        <tr>
            <th>第三方承保公司：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.InsuranceCompany, new { Value = "平安产险", @class = "disabled-element" })
            </td>
            <th></th>
            <td>
            </td>
        </tr>
        <tr>
            <th>第三方唯一编号：<span class="red">*</span></th>
            <td>
                 @Html.TextBoxFor(m => m.InsuranceOrder.ThirdUniqueNumber, new { placeholder = "非团体投保为保单号", validate = "{isRightfulStringNounderline:true,required:true,messages:{required:'请填写第三方唯一编号'}}", maxlength = 50 })
            </td>
            <th>第三方保单号：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.ThirdOrderNO, new { validate = "{isRightfulStringNounderline:true,required:true,messages:{required:'请填写第三方保单号'}}", maxlength = 50 })
            </td>
        </tr>
        <tr>
            <th>承保公司分公司：<span class="red">*</span></th>
            <td>
                <select name="InsuranceOrder.InsuranceCompanyBranch" id="InsuranceOrder_InsuranceCompanyBranch" validate="{required:true,messages:{required:'选择承保公司分公司'}}">
                    <option value="" selected="">选择承保公司分公司</option>
                    <option value="湖南分公司">湖南分公司</option>
                    <option value="上海分公司">上海分公司</option>
                    <option value="陕西分公司">陕西分公司</option>
                    <option value="四川分公司">四川分公司</option>
                    <option value="广东分公司">广东分公司</option>
                    <option value="江苏分公司">江苏分公司</option>
                    <option value="深圳分公司">深圳分公司</option>
                    <option value="苏州分公司">苏州分公司</option>
                </select>
            </td>
            <th>被保险设备类型：<span class="red">*</span></th>
            <td>
                @Html.DropDownListFor(m => m.InsuranceOrder.DeviceType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceOrderDeviceType)), new { validate = "{required:true,messages:{required:'请选择被保险设备类型！'}}" })
            </td>
        </tr>
        <tr>
            <th>品牌：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.ProductBrandName)
                @Html.HiddenFor(m => m.InsuranceOrder.ProductBrandId)
            </td>
            <th>销售商户名称：<span class="red">*</span></th>
            <td>
                @Html.DropDownListFor(m => m.InsuranceOrder.SaleVendorId, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(SaleVendorEnums)), new { validate = "{required:true,messages:{required:'请选择销售商户名称！'}}" })
                @Html.HiddenFor(m => m.InsuranceOrder.SaleVendorName)
            </td>
        </tr>
        <tr>
            <th>机型：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.ProductModelName)
                @Html.HiddenFor(m => m.InsuranceOrder.ProductModelId)
            </td>
            <th>设备识别码：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.IMEI, new { validate = "{isRightfulStringNounderline:true}",maxlength =50 })
            </td>
        </tr>
        <tr>
            <th>被保险人姓名：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.UserName, new { validate = "{required:true,messages:{required:'请填写被保险人姓名'}}",maxlength = 20 })
            </td>
            <th>投保日期</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.CreateOrderTime, new { @class = "Wdate", onclick = "WdatePicker({maxDate:'" + DateTime.Now.ToString("yyyy-MM-dd") + "'})" })
            </td>
        </tr>
        <tr>
            <th>被保险人电话：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.UserPhone, new { validate = "{required:true,isTelphone:true,messages:{required:'请填写被保险人电话'}}",maxlength =11 })
            </td>
            <th>保险起期：</th>
            <td>
                <!--日期的并且使用||符合链接-->
                @Html.TextBoxFor(m => m.InsuranceOrder.ServiceStartTime, new { @class = "Wdate", onclick = "WdatePicker({maxDate:'#F{$dp.$D(\\'InsuranceOrder_ServiceEndTime\\')||\\'" + DateTime.Now.ToString("yyyy-MM-dd") + "\\'}'})" })
            </td>
        </tr>
        <tr>
            <th>证件号码：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.CertificateNO, new { maxlength = 50 })
            </td>
            <th>保险止期：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.ServiceEndTime, new { @class = "Wdate", onclick = "WdatePicker({minDate:'#F{$dp.$D(\\'InsuranceOrder_ServiceStartTime\\')}'})" })
            </td>
        </tr>
        <tr>
            <th>保额：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceOrder.InsuredAmount, new { onkeyup = "onlyInputDecimal(this)",maxlength=10 })
            </td>
            <th class="w200">出险日期：</th>
            <td>@Html.TextBoxFor(m => m.ExpectAccidentDate, new { @class = "Wdate", onclick = "WdatePicker({maxDate:'" + DateTime.Now.ToString("yyyy-MM-dd") + "'})" })</td>
        </tr>
    </table>
    <div class="hidden">
        <h4>出险信息</h4>
        <table class="table table-responsive table-bordered table-hover">
            <tr>
                <th class="w200">出险地点：</th>
                <td class="w-p39">
                    @Html.DropDownListFor(m => m.ProvinceId, selectList)
                    @Html.DropDownListFor(m => m.CityId, new List<SelectListItem>())
                </td>
            </tr>
            <tr>
                <th>出险地点（详细地址）：</th>
                <td colspan="3">
                    @Html.TextBoxFor(m => m.AccidentAddress, new { validate = "{required:true,messages:{required:'出险地点（详细地址）必填！'}}", @class = "w-p98" })
                </td>
            </tr>
            <tr>
                <th>出险经过说明：</th>
                <td colspan="3">
                    @Html.TextAreaFor(m => m.AccidentProsess, new { validate = "{required:true,messages:{required:'出险经过说明必填！'}}", @class = "w-p98" })
                </td>
            </tr>
        </table>
    </div>
    <div class="form-actions">
        <input id="btnAuditAndPass" class="btn btn-primary Edit-R" type="submit" value="提交">
    </div>
}
@section scripts
{
    @Scripts.Render("~/bundles/autocomplete")
    @Styles.Render("~/Content/autocomplete")
    <script type="text/javascript">
        $(function () {
            saleVendorIdChange();
            productTypeChange();
            provinceChange();

            $("#InsuranceOrder_SaleVendorId").change(function () {
                saleVendorIdChange();
            });
            $("#ProvinceId").change(function () {
                provinceChange();
            });
            $("#InsuranceOrder_ProductBrandName").autocomplete("/Common/GetProductBrandList", {
                cacheLength: 0, //缓存
                delay: 230, //延迟
                dataType: "json",
                parse: function(data) {
                    try {
                        return $.map(data, function(row) {
                            return {
                                data: row,
                                value: row.Value,
                                result: row.Text
                            }
                        });
                    } catch (e) {
                        return "";
                    }
                },
                formatItem: function(item, i, max) {
                    return item.Text;
                },
                formatResult: function(item) {
                    return item.Text;
                }
            }).result(function(event, data, formatted) {
                try {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductBrandName", "ProductBrandId")).val(data.Value);
                } catch (e) {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductBrandName", "ProductBrandId")).val("");
                }
            });

            $("#InsuranceOrder_ProductModelName").autocomplete("/Common/GetProductModelListByBrandIdAndModelName", {
                cacheLength: 0, //缓存
                delay: 230, //延迟
                extraParams: { BrandId: function() { return $("#InsuranceOrder_ProductBrandId").val() } },
                dataType: "json",
                parse: function(data) {
                    try {
                        return $.map(data, function(row) {
                            return {
                                data: row,
                                value: row.Value,
                                result: row.Text
                            }
                        });
                    } catch (e) {
                        return "";
                    }
                },
                formatItem: function(item, i, max) {
                    return item.Text;
                },
                formatResult: function(item) {
                    return item.Text;
                }
            }).result(function(event, data, formatted) {
                try {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductModelName", "ProductModelId")).val(data.Value);
                } catch (e) {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductModelName", "ProductModelId")).val("");
                }
            });
        });

        function provinceChange() {
            var provinceID = $("#ProvinceId").val();
            $.ajax({
                url: "/Common/GetCityList?provinceID=" + provinceID,
                success: function(data) {
                    var html = "";
                    $("#CityId").html(html);
                    if (data && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value='";
                            html += data[i].Value;
                            html += "'>" + data[i].Text;
                            html += "</option>";
                        }
                        $("#CityId").html(html);
                    }
                }
            });
        }

        function productTypeChange() {
            var typeName = $("#InsuranceOrder_ProductTypeId option:selected").text();
            $("#InsuranceOrder_ProductTypeName").val(typeName);
        }

        function saleVendorIdChange() {
            var typeName = $("#InsuranceOrder_SaleVendorId option:selected").text();
            $("#InsuranceOrder_SaleVendorName").val(typeName);
        }
    </script>
}
